package cn.seocoo.platform.api.controller;

import cn.seocoo.platform.api.util.JSONResult;
import cn.seocoo.platform.api.util.PageBean;
import cn.seocoo.platform.information.dto.InformationDto;
import cn.seocoo.platform.information.service.IInformationService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: ApiInformationController
 * @description: 消息管理
 * @author: wujian
 * @Date: 2019-12-26 09:26
 **/
@RequestMapping("/api/information")
@RestController
public class ApiInformationController {
    @Autowired
    private IInformationService informationService;

    /**
     * @Author WuJian
     * @Description //获取用户的系统消息
     * @Date 9:54 2019/12/26
     * @Param [appUserId]
     * @return cn.seocoo.platform.common.core.domain.AjaxResult
     **/
    @GetMapping("/getInfoList")
    public JSONResult getInfoList(Integer appUserId, Integer pageNum,Integer pageSize){

        PageHelper.startPage(pageNum == null? 1:pageNum,pageSize == null?10:pageSize);
        List<InformationDto> list =  informationService.getInfoListByAppUserId(appUserId);
        return JSONResult.ok(new PageBean<>(list));
    }

    /**
     * @Author WuJian
     * @Description //获取单个消息
     * @Date 9:55 2019/12/26
     * @Param [id]
     * @return cn.seocoo.platform.common.core.domain.AjaxResult
     **/
    @GetMapping("/getInfo")
    public JSONResult getInfo(Integer id){
        InformationDto dto =  informationService.getInfoById(id);
        //将消息状态改为已读
        informationService.updateInformationForRead(id);
        return JSONResult.ok(dto);
    }



}
